package br.usp.ime.lab.main;
import java.io.File;
import java.util.Vector;

import recoder.ParserException;
import recoder.abstraction.Method;
import recoder.java.ProgramElement;
import recoder.java.declaration.ClassDeclaration;
import br.usp.ime.instrumentation.Instrumentation;
import br.usp.ime.lab.analyzer.ConditionAnalyzerImpl;

public class Main {
	
	
	public static void main(String[] args) {
		doInstrumentation("C:/Users/Renato/workspace/EngSoft/TestMcdc/src", "C:/Users/Renato/workspace/EngSoft/TestMcdc/src");
	}
	
	public static void doInstrumentation(String sourcePackage, String instrumentedPackage) {
		ConditionAnalyzerImpl ca = new ConditionAnalyzerImpl();
		Vector<Method> metodos = ca.getAst(sourcePackage, "");
		
		File f1 = new File(sourcePackage + "/../decisoes");
		f1.mkdir();
		File f2 = new File(sourcePackage + "/../condicoes");
		f2.mkdir();
		File f3 = new File(sourcePackage + "/../mcdc");
		f3.mkdir();
		
		
		// MC/DC
		for (Method m : metodos) {
			ProgramElement p = (ProgramElement)m;
			ClassDeclaration className;
			while (!(p.getASTParent() instanceof ClassDeclaration)) {
				p = p.getASTParent();
			}
			className = (ClassDeclaration) p.getASTParent();
			
			ca.getAllDecisions(sourcePackage + "/../decisoes/" + "decisoes_" + className.getName() + "_" + m.getName() + ".xml", m);
			ca.getAllConditions(sourcePackage + "/../condicoes/" + "condicoes_" + className.getName() + "_" + m.getName() + ".xml", m);
			
			ca.getAllMCDC(sourcePackage + "/../mcdc/" + "mcdc_" + className.getName() + "_" + m.getName() + ".xml", m);

				
		}
		try {
			Instrumentation.getInstance().instrumentatePackage(sourcePackage, "", instrumentedPackage);
		} catch (ParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
